const fs = require('fs');
const path = require('path');
const { decrypt, findFilePath } = require('../../src/tool');
const sourcePath = path.resolve(__dirname);
const allDatFiles = [];
findFilePath(sourcePath, '.dat', allDatFiles);

function checkFilesIsDecode() {
  for (let p of allDatFiles) {
    const content = fs.readFileSync(p);
    const firstCharacter = content.slice(0, 8).toString();
    if (firstCharacter[0] !== '<') {
      const decryptContent = decrypt(content);
      fs.writeFileSync(p, decryptContent);
    }
  }
}

function run() {
  checkFilesIsDecode();
}

run();
